<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>layerSwitcher</title>
  <link rel="stylesheet" href="../../dist/hmap.css" type="text/css">
  <style type="text/css">
    html, body, #map {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
  </style>
</head>
<body>
<div id="map"></div>
<script src="../../dist/hmap.js" type="text/javascript"></script>
<script type="text/javascript">
  var Map = new HMap('map', {
    controls: {
      zoom: false,
      rotate: false
    },
    view: {
      center: [12118909.300259633, 4086043.1061670054],
      zoom: 5,
    },
    baseLayers: [
      {
        layerName: 'OSM',
        layerType: 'OSM',
        isDefault: true,
        layerUrl: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
      },
      {
        layerName: 'Google',
        layerType: 'Google',
        isDefault: false,
        layerUrl: 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}'
      },
      {
        layerName: 'GaoDe',
        layerType: 'GaoDe',
        isDefault: false,
        layerUrl: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}'
      }
    ]
  });
  Map.on('loadMapSuccess', function (event) {
    if (event) {
      var config_ = [
        {
          layerName: 'GaoDe',
          name: '高德',
          icon: '../assets/images/maptype_vector.png'
        },
        {
          layerName: 'OSM',
          name: 'OSM',
          icon: '../assets/images/maptype_pano.png'
        },
        {
          layerName: 'Google',
          name: '谷歌',
          icon: '../assets/images/maptype_yunran.png'
        }
      ]
      var LayerSwitcher = new ol.control.LayerSwitcher({
        itemWidth: 86,
        itemHeight: 60,
        layers: config_
      })
      Map.addControl(LayerSwitcher)
      var tt = Map.getLayersArrayByKeyValue('isBaseLayer', true) // polyfill
      LayerSwitcher.baseLayers_ = tt
      console.log(tt)
    }
  })
</script>
</body>
</html>
